package com.wfw.client.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * Created by yuzhongbo on 2018/9/14.
 */
@Service
public class HystrixService {

    @Autowired
    RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "hystrixError")
    public String hystrix(String name) {
        try {
            System.out.println(name);
            if(name.equals("open")){
                Thread.sleep(6000L);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return name;
        //return restTemplate.getForObject("http://eureka-client/hystrix?name="+name, String.class);
    }

    public String hystrixError(String name) {
        return "hi,"+name+",sorry,error!";
    }
}
